<?php

class ApiController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete', // we only allow deletion via POST request
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('subarea'),
				'users'=>array('*'),
			)
		);
	}

	/**
	 * 注册接口.
	 */
	public function actionSubarea($lat=0, $lng=0)
	{
		header('Content-type: application/json;charset=utf-8');
		
		$models = Subarea::model()->findAll(" 1=1 order by id desc");

		$ret = array();
		foreach($models as $v)
		{
			$ret[] = array("id" => $v['id'],
				"lat" => $v['lat'],
				"lng" => $v['lng'],
				"description" => $v['description'],
				"title" => $v['title'],
				"adds" => $v['adds'],
				"hotline" => $v['hotline'],
				"evaluation" => $v['evaluation'],
				"percost" => $v['percost'],
				"createtime" => strtotime($v['createtime'])<0?0:strtotime($v['createtime'])
				);
		}

		 
		
		echo json_encode(array('code'=> 0 ,'message'=> "", 'data'=>$ret));

		// echo '{"code": 1001 ,"message": "缺少参数或者参数不正确"}';
	}




}
